let reg={
    Username:/^[a-z]\w{6,9}$/,
    password:/^[a-zA-Z]\w{6,9}$/,
    name:/^[\u4E00-\u9FA5]{2,4}$/,
    sex:/^(男|女)$/,
    tel:/^[1][3-9][0-9]{9}$/
};

let oBtn2=$('#sign-in-btn2');
let oBtn3=$('#sign-in-btn3');
let oInp1=$('#sign-in-inp1');
let oInp2=$('#sign-in-inp2');
let oInp3=$('#sign-in-inp3');
let oInp4=$('#sign-in-inp4');
let oInp5=$('#sign-in-inp5');
let oInp13=$('#sign-in-inp13');
let oInp14=$('#sign-in-inp14');
let oFlag=true;
function test(obj){
    obj = $(obj);
    let oNext=obj.next();
    let str=obj.val();
    if(!str.trim()){
        oNext.text('不能为空');
        oNext.addClass('red');
        return false
    }
    /*console.log(obj.attr("name"));*/
    if(reg[obj.attr("name")].test(str)){
        oNext.text('√');
        oNext.addClass('green');
        return true
    }else{
        oNext.text('×');
        oNext.addClass('red');
        return false
    }
}
oInp1.blur(function () {
    test(this)
});
oInp2.blur(function () {
    test(this)
});

oInp3.blur(function(){
    let oNext1=oInp3.next();
    oNext1.text('√');
    oNext1.addClass('green');
});
oInp4.blur(function () {
    test(this)
});
oInp13.blur(function () {
    test(this)
});
oInp14.blur(function(){
    let oNext8=oInp14.next();
    oNext8.text('√');
    oNext8.addClass('green');
});
oInp5.blur(function(){
    let oNext2=oInp5.next();
    oNext2.text('√');
    oNext2.addClass('green');
});

let json1={
    "aInforamtion":[{"name":"张三", "sex":"男", "day":18, "tel":1888888888, "adress":"四川省成都市"}]
};

oBtn3.click(function(){
    let aA=document.getElementsByClassName('aaa');

    for(let i=0;i<aA.length;i++){
        if(!test(aA[i])){
            oFlag=false;
        }
    }
    if(!oFlag){
        oBtn2.attr("disabled",false);
        return false
    }else{
        oBtn2.attr("disabled",false);
    }
    let oName=oInp1.val();
    let oSex=oInp2.val();
    let oDay=oInp3.val();
    let oTel=oInp4.val();
    let oAdress=oInp5.val();
    json1.aInforamtion.splice(0,1);
    json1.aInforamtion.push({
        "name":oName, "sex":oSex, "day":oDay, "tel":oTel, "adress":oAdress
    });

    let str1=JSON.stringify(json1);
    localStorage.setItem('data2',str1);


});

let oUser=document.getElementById('sign-in-username');
let oPass=document.getElementById('sign-in-password');
let oBtn1=document.getElementById('sign-in-btn');
let oInp6=document.getElementById('sign-in-inp6');
let oInp7=document.getElementById('sign-in-inp7');
let oBtn4=document.getElementById('sign-in-btn4');
let oBtn5=document.getElementById('sign-in-btn5');
let oInp10=document.getElementById('sign-in-inp10');
let oInp11=document.getElementById('sign-in-inp11');

let json={
    "aUser":[{"user":"aaa","pass":111,"type":1},{"user":"bbb","pass":222,"type":2},{"user":"ccc","pass":333,"type":3}]
};

oBtn1.onclick=function () {
    let str=JSON.stringify(json);
    localStorage.setItem('data',str);
    let data=JSON.parse(localStorage.getItem('data'));
    let aUser=json.aUser;
    let sName=oUser.value;
    let sPass=oPass.value;

    for(let i=0;i<aUser.length;i++){
        if(aUser[i].user==sName){
            if(aUser[i].pass==sPass){
                window.location.href='index.html?type='+aUser[i].type;
                return;
            }else{
                alert('账号或密码错误');
                return;
            }
        }
    }
    alert('账号错误');
};
oBtn4.onclick=function () {
    let sName=oInp6.value;
    let sPass=oInp7.value;
    if(localStorage.getItem(sName)){
        alert('此账号已经存在');
    }else{
        /*localStorage.setItem(sName,sPass);*/
        json.aUser.push({
            "user":sName,"pass":sPass,"type":0,
        });
        let str=JSON.stringify(json);
        localStorage.setItem('data',str);
        alert('成功')
    }
};


oBtn5.onclick=function () {
    let sName1=oInp10.value;
    let sPass1=oInp11.value;

     /*localStorage.setItem(sName1,sPass1);*/

    json.aUser.splice(3,1);
     json.aUser.push({
         "user": sName1, "pass": sPass1,"type":0,
     });

    let str=JSON.stringify(json);
    localStorage.setItem('data',str);
        alert('成功')
    };

    /*console.log(json)*/


oInp6.onblur=function(){
    test(this)
};
oInp7.onblur=function(){
    test(this)
};


let oInp8=$('#sign-in-inp8');
let oInp9=$('#sign-in-inp9');
oInp8.blur(function () {
    test(this)
});
oInp9.blur(function () {
    let oNext3=oInp9.next();
    oNext3.text('√');
    oNext3.addClass('green');
});









